<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="org.slf4j.Logger" %>
<%@ page import="org.slf4j.LoggerFactory" %>
<%@ page import="com.tencent.albert.weixin.driver.utils.JspLogger" %>
<%@ page import="java.util.Map" %>
<%@ page import="org.apache.commons.collections.MapUtils" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="com.tencent.albert.weixin.driver.utils.WeixinUtil" %>
<%@ page import="com.tencent.albert.weixin.driver.bean.WxUserInfo" %>
<%@ page import="com.tencent.albert.spring.shiro.SsoOpenIdCryptos" %>
<%@ page import="org.apache.shiro.web.servlet.SimpleCookie" %>
<%--
  Created by IntelliJ IDEA.
  User: albertzhu
  Date: 15/2/15
  Time: 下午2:56
  To change this template use File | Settings | File Templates.
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%
    String code = request.getParameter("code");
    String state = request.getParameter("state");
    if (!StringUtils.isBlank(code)) {
        String openId = WeixinUtil.getOpenId(code);
        if (null != openId) {
            SsoOpenIdCryptos.encryptOpenId(openId);
            SimpleCookie simpleCookie = new SimpleCookie(SsoOpenIdCryptos.cookie_name);
            simpleCookie.setValue(SsoOpenIdCryptos.encryptOpenId(openId));
            simpleCookie.setPath("/");
            simpleCookie.saveTo(request, response);
            response.sendRedirect("http://www.52xiaoluo.com/user/login/sso");
        }
    } else {
        String ua = request.getHeader("user-agent");
        JspLogger.info("oauth_base",
                "receive null code oath request from "+request.getHeader("x-real-ip")
                        +":"+request.getRequestURL()+"?"+request.getQueryString()+" ua:"+ua,null);
    }

%>
